D 		 [0-9]
L 		 [a-zA-Z_]
%{
extern "C" {
int yywrap(void);
int yylex(void);
}

#include <iostream>
#include <string>
#define YYSTYPE node*

#include "head.h"
#include "frame.tab.h"
int yylex();

extern YYSTYPE yylval;


void count();
%}
%%
"#"[^\n]*$       { /* Ignore Comments */ }
"and" 		 { return(AND); }
"bool" 		 { return(BOOL); }
"def" 		 { return(DEF); }
"else" 		 { return(ELSE); }
"false" 	 { return(FALSE); }
"float" 	 { yylval = new terminal("float");return(FLOAT); }
"for" 		 { return(FOR); }
"if" 		 { return(IF); }
"image"		 { return(IMAGE); }
"include"	 { return(INCLUDE); }
"int"		 { yylval = new terminal("int");return(INT); }
"or" 		 { return(OR); }
"not" 		 { yylval = new terminal("not"); return(NOT); }
"pixel" 	 { yylval = new terminal("pixel");return(PIXEL); }
"print" 	 { return(PRINT); }
"return" 	 { return(RETURN); } 
"to" 		 { return(TO); }
"true" 		 { return(TRUE); }
"video" 	 { yylval = new terminal("video");return(VIDEO); }
"void" 		 { return(VOID); }
"while"		 { return(WHILE); }


{L}({L}|{D})* 	  { node *n = new terminal(yytext);yylval = n;return(IDENTIFIER); }

{D}+("."{D}+)? 	  { node *n = new terminal(atof(yytext)); yylval = n;return(CONSTANT); }
\"(\\.|[^\\"])*\" {node *n = new terminal(yytext);yylval = n; return(STRING_LITERAL); }


"<-" 	         { return(PARAM_OP); }

"<=" 		 { return(LE_OP); }
">=" 		 { return(GE_OP); }
"==" 		 { return(EQ_OP); }
"!=" 		 { return(NE_OP); }

"<<" 		 { return(INPUT_OP); }
">>" 		 { return(OUTPUT_OP); }
"**" 		 { return(ITOV_OP); }
"%>" 		 { return(CUT_OP); }
"=>" 		 { return(RESIZE_OP); }
"*>" 		 { return(ZOOM_OP); }
"[<" 		 { return(LDBRACE); }
">]" 		 { return(RDBRACE); }

"@" 		 { return('@'); }

";" 		 { return(';'); }
"{" 		 { return('{'); }
"}" 		 { return('}'); }
"," 		 { return(','); }
":" 		 { return(':'); }
"=" 		 { return('='); }
"(" 		 { return('('); }
")" 		 { return(')'); }
"[" 		 { return('['); }
"]" 		 { return(']'); }
"." 		 { return('.'); }
"&" 		 { return('&'); }
"|" 		 { return('|'); }
"-" 		 { node *n = new terminal("unary_minus"); yylval = n;return('-'); }
"+" 		 { return('+'); }
"*" 		 { return('*'); }
"/" 		 { return('/'); }
"%" 		 { return('%'); }
"<" 		 { return('<'); }
">" 		 { return('>'); }
"~" 		 { return('~'); }


[ \t\v\n\f] 	 { count(); }
. 		 { /* ignore bad characters */ }
%%
int yywrap(void)
{
 	return 1;
}
int column = 0;

void count()
{
 int i;

 for (i = 0; yytext[i] != '\0'; i++)
 	 if (yytext[i] == '\n')
 		 column = 0;
 	 else if (yytext[i] == '\t')
 		 column += 8 - (column % 8);
 	 else
 		 column++;

 ECHO;
}

